package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.allocationOrder.AllocationOrderDto;
import com.java110.intf.IAllocationOrderInnerServiceSMO;
import com.java110.mall.goods.dao.IAllocationOrderServiceDao;
import com.java110.po.account.AllocationOrderPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 调拨单内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class AllocationOrderInnerServiceSMOImpl extends BaseServiceSMO implements IAllocationOrderInnerServiceSMO {

    @Autowired
    private IAllocationOrderServiceDao allocationOrderServiceDaoImpl;


    @Override
    public int saveAllocationOrder(@RequestBody AllocationOrderPo allocationOrderPo) {
        int saveFlag = 1;
        allocationOrderServiceDaoImpl.saveAllocationOrderInfo(BeanConvertUtil.beanCovertMap(allocationOrderPo));
        return saveFlag;
    }

    @Override
    public int updateAllocationOrder(@RequestBody AllocationOrderPo allocationOrderPo) {
        int saveFlag = 1;
        allocationOrderServiceDaoImpl.updateAllocationOrderInfo(BeanConvertUtil.beanCovertMap(allocationOrderPo));
        return saveFlag;
    }

    @Override
    public int deleteAllocationOrder(@RequestBody AllocationOrderPo allocationOrderPo) {
        int saveFlag = 1;
        allocationOrderPo.setStatusCd("1");
        allocationOrderServiceDaoImpl.updateAllocationOrderInfo(BeanConvertUtil.beanCovertMap(allocationOrderPo));
        return saveFlag;
    }

    @Override
    public List<AllocationOrderDto> queryAllocationOrders(@RequestBody AllocationOrderDto allocationOrderDto) {

        //校验是否传了 分页信息

        int page = allocationOrderDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            allocationOrderDto.setPage((page - 1) * allocationOrderDto.getRow());
        }

        List<AllocationOrderDto> allocationOrders = BeanConvertUtil.covertBeanList(allocationOrderServiceDaoImpl.getAllocationOrderInfo(BeanConvertUtil.beanCovertMap(allocationOrderDto)), AllocationOrderDto.class);

        return allocationOrders;
    }


    @Override
    public int queryAllocationOrdersCount(@RequestBody AllocationOrderDto allocationOrderDto) {
        return allocationOrderServiceDaoImpl.queryAllocationOrdersCount(BeanConvertUtil.beanCovertMap(allocationOrderDto));
    }

    public IAllocationOrderServiceDao getAllocationOrderServiceDaoImpl() {
        return allocationOrderServiceDaoImpl;
    }

    public void setAllocationOrderServiceDaoImpl(IAllocationOrderServiceDao allocationOrderServiceDaoImpl) {
        this.allocationOrderServiceDaoImpl = allocationOrderServiceDaoImpl;
    }
}
